package bd.proiect;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/*
 * Formular pentru adaugarea Originii de plante
 * Exemplificare:
 * 		EditText
 * 		Adaugare in Baza de date
 */


public class AddOrigin extends Activity{
	
	DataBase bs;
	EditText ed;
	
	@Override
	  public void onCreate(Bundle savedInstanceState) {
	     super.onCreate(savedInstanceState);
	     setContentView(R.layout.addorigin);
	     
	     ed = new EditText(this);
         ed = (EditText)findViewById(R.id.addorigin_edit);
         
         bs = new DataBase(this);
	     Button SaveButton = (Button) findViewById(R.id.addorigin_button);
	     SaveButton.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	String originName = ed.getText().toString();
	    	    try{
    				bs.createDataBase();
    				bs.openDataBase();
    				bs.insertOrigin(originName);
    				bs.close();
    				
	    	    }catch(Exception e){
	    	    	ed.setText("buba" + e);
    			}
	    	    finish();
	         	}
	         }
	     	); 
         
	     }

}
